What is buble?
Bublé is a JavaScript compiler that takes your ES2015+ code and turns it into code that can run in older browsers. It is designed to be fast and to produce compact output.
What are buble's main functionalities?
Transpiling ES6 to ES5
Bublé can transpile modern ES6+ syntax to ES5, making it compatible with older browsers. This example shows how an arrow function is transformed into a regular function.
const buble = require('buble');
const result = buble.transform(`const add = (a, b) => a + b;`);
console.log(result.code); // 'var add = function (a, b) { return a + b; };'
Source Maps
Bublé can generate source maps, which are useful for debugging. This example shows how to generate a source map for the transformed code.
const buble = require('buble');
const result = buble.transform(`const add = (a, b) => a + b;`, { source: 'input.js', file: 'output.js' });
console.log(result.map);
Custom Transforms
Bublé allows you to customize which transformations to apply. This example shows how to disable the transformation of ES6 classes.
const buble = require('buble');
const result = buble.transform(`class Person { constructor(name) { this.name = name; } }`, { transforms: { classes: false } });
console.log(result.code);
Other packages similar to buble
babel
Babel is a widely-used JavaScript compiler that supports a wide range of plugins and presets for transforming ES6+ code to ES5. It is more feature-rich and extensible compared to Bublé, but it can be slower and produce larger output.
typescript
TypeScript is a superset of JavaScript that adds static types. It also includes a compiler that can transpile TypeScript (and modern JavaScript) to ES5. While it offers more features like type checking, it is more complex to set up and use compared to Bublé.
esbuild
esbuild is an extremely fast JavaScript bundler and minifier. It can also transpile modern JavaScript to older versions. It is known for its speed and efficiency, but it is less configurable than Babel.
Bublé
The blazing fast, batteries-included ES2015 compiler
Quickstart
Via the command line...
npm install -g buble
buble input.js > output.js
...or via the JavaScript API:
var buble = require( 'buble' );
var result = buble.transform( source );
License
MIT